package com.sojson.controller.po;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sojson.entity.po.FileDepot;
import com.sojson.result.Result;
import com.sojson.service.FileDepotService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 文件库控制器
 * 
 * @author liu
 * @date 2021-05-26
 */
@Api(tags = "文件管理")
@RestController
@RequestMapping("/fileDepot")
public class FileDepotController {

    @Autowired
    private FileDepotService fileDepotService;

    /**
     * 单条插入
     * 
     * @param fileDepot
     * @return
     */
    @PostMapping("/insert")
    @PreAuthorize("@ss.hasPermi('/fileDepot/insert')")
    @ApiOperation("给文件添加一条数据")
    public Result<Integer> insert(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.insert(fileDepot));
    }

    /**
     * 批量插入
     * 
     * @param fileDepot
     * @return
     */
    @PostMapping("/insertList")
    @PreAuthorize("@ss.hasPermi('/fileDepot/insertList')")
    @ApiOperation("给文件添加多条数据")
    public Result<Integer> insertList(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.insertList(fileDepot));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param fileDepot
     * @return
     */
    @DeleteMapping("/deleteByDto")
    @PreAuthorize("@ss.hasPermi('/fileDepot/deleteByDto')")
    @ApiOperation("通过对象批量删除文件数据(物理删除)")
    public Result<Integer> deleteByDto(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.deleteByDto(fileDepot));
    }

    /**
     * 统计全部数量
     * 
     * @return
     */
    @GetMapping("/countAll")
    @PreAuthorize("@ss.hasPermi('/fileDepot/countAll')")
    @ApiOperation("统计文件全部数据(包含逻辑删除的)")
    public Result<Integer> countAll() {
        return Result.success(fileDepotService.countAll());
    }

    /**
     * 查询所有
     * 
     * @return
     */
    @GetMapping("/listAll")
    @PreAuthorize("@ss.hasPermi('/fileDepot/listAll')")
    @ApiOperation("查询文件所有数据(包含逻辑删除的)")
    public Result<List<FileDepot>> listAll() {
        return Result.success(fileDepotService.listAll());
    }

    /**
     * 根据对象统计数量
     * 
     * @param fileDepot
     * @return
     */
    @GetMapping("/countByDto")
    @PreAuthorize("@ss.hasPermi('/fileDepot/countByDto')")
    @ApiOperation("根据对象统计文件数据")
    public Result<Integer> countByDto(FileDepot fileDepot) {
        return Result.success(fileDepotService.countByDto(fileDepot));
    }

    /**
     * 根据对象查询
     * 
     * @param fileDepot
     * @return
     */
    @GetMapping("/listByDto")
    @PreAuthorize("@ss.hasPermi('/fileDepot/listByDto')")
    @ApiOperation("根据对象查询文件数据")
    public Result<List<FileDepot>> listByDto(FileDepot fileDepot) {
        return Result.success(fileDepotService.listByDto(fileDepot));
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    @PreAuthorize("@ss.hasPermi('/fileDepot/deleteById/{id}')")
    @ApiOperation("通过id删除文件数据(物理删除)")
    @ApiImplicitParam(name = "id", value = "id")
    public Result<Integer> deleteById(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(fileDepotService.deleteById(id));
    }

    /**
     * 通过id数组删除(物理删除)
     * 
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/fileDepot/deleteByIds')")
    @ApiOperation("通过id数组删除文件数据(物理删除)")
    @ApiImplicitParam(name = "ids", value = "id数组")
    public Result<Integer> deleteByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(fileDepotService.deleteByIds(ids));
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param fileDepot
     * @return
     */
    @PutMapping("/updateAllById")
    @PreAuthorize("@ss.hasPermi('/fileDepot/updateAllById')")
    @ApiOperation("通过id更新文件数据(全部更新)")
    public Result<Integer> updateAllById(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.updateAllById(fileDepot));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param fileDepot
     * @return
     */
    @PutMapping("/updateAllByIdList")
    @PreAuthorize("@ss.hasPermi('/fileDepot/updateAllByIdList')")
    @ApiOperation("通过id列表更新文件数据(全部更新)(更新内容相同)")
    public Result<Integer> updateAllByIdList(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.updateAllByIdList(fileDepot));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param fileDepot
     * @return
     */
    @PutMapping("/updateDtoListAllById")
    @PreAuthorize("@ss.hasPermi('/fileDepot/updateDtoListAllById')")
    @ApiOperation("通过id列表更新文件数据(全部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListAllById(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.updateDtoListAllById(fileDepot));
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param fileDepot
     * @return
     */
    @PutMapping("/updateById")
    @PreAuthorize("@ss.hasPermi('/fileDepot/updateById')")
    @ApiOperation("通过id更新文件数据(局部更新)")
    public Result<Integer> updateById(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.updateById(fileDepot));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param fileDepot
     * @return
     */
    @PutMapping("/updateByIdList")
    @PreAuthorize("@ss.hasPermi('/fileDepot/updateByIdList')")
    @ApiOperation("通过id列表更新文件数据(局部更新)(更新内容相同)")
    public Result<Integer> updateByIdList(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.updateByIdList(fileDepot));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param fileDepot
     * @return
     */
    @PutMapping("/updateDtoListById")
    @PreAuthorize("@ss.hasPermi('/fileDepot/updateDtoListById')")
    @ApiOperation("通过id列表更新文件数据(局部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListById(@RequestBody FileDepot fileDepot) {
        return Result.success(fileDepotService.updateDtoListById(fileDepot));
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @PreAuthorize("@ss.hasPermi('/fileDepot/findById/{id}')")
    @ApiOperation("通过id查询文件数据")
    @ApiImplicitParam(name = "id", value = "id")
    public Result<FileDepot> findById(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(fileDepotService.findById(id));
    }

    /**
     * 通过id数组查询
     * 
     * @param ids
     * @return
     */
    @GetMapping("/findByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/fileDepot/findByIds/{ids}')")
    @ApiOperation("通过id数组查询文件数据")
    @ApiImplicitParam(name = "ids", value = "id数组")
    public Result<List<FileDepot>> findByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(fileDepotService.findByIds(ids));
    }

    /**
     * 通过对象查询id列表
     * 
     * @param fileDepot
     * @return
     */
    @GetMapping("/findIdByDto")
    @PreAuthorize("@ss.hasPermi('/fileDepot/findIdByDto')")
    @ApiOperation("通过对象查询文件id列表")
    public Result<List<Integer>> findIdByDto(FileDepot fileDepot) {
        return Result.success(fileDepotService.findIdByDto(fileDepot));
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     */
    @DeleteMapping("/clear")
    @PreAuthorize("@ss.hasPermi('/fileDepot/clear')")
    @ApiOperation("清空文件数据(物理清空)")
    public Result<Integer> clear() {
        return Result.success(fileDepotService.clear());
    }

    /**
     * 清空旧文件
     * 
     * @return
     */
    @DeleteMapping("/clearFile")
    @PreAuthorize("@ss.hasPermi('/fileDepot/clearFile')")
    @ApiOperation("清空旧文件")
    public Result<Integer> clearFile() {
        fileDepotService.clearFile();
        return Result.success();
    }

}